<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Campaign_Version
 *
 * @author Samuel Pulta
 */
class Campaign_Version extends Brochure {
    //put your code here
    
    public $version_id;
    public $campaign_id;
    public $user_id;
    public $date_created;
    public $version_name;
    public $version;
    public $quarter;
    public $title;
    public $campaign_list_id;
    public $brand_story;
    public $description;
    public $is_active;

    
    public function __construct($db, $id) {
        $this->init($db, $id);
    }
    
    public function init($db, $id){
        $this->db = $db;
        $this->tblname = TB_CAMPAIGN_VERSION;
        $this->id = $id;
        
            if($id){
                $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE version_id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "row");
    
                $this->id   =   $result['version_id'];
                $this->campaign_id   =   $result['campaign_id'];
                $this->quarter = $result['quarter'];
                $this->user_id   =   $result['user_id'];
                $this->date_created = $result['date_created'];
                $this->version_name   =   $result['version_name'];
                $this->version   =   $result['version'];
                $this->title   =   $result['title'];
                $this->campaign_list_id   =   $result['campaign_list_id'];	
                $this->brand_story   =   $result['brand_story'];
                $this->description   =   $result['description'];
                $this->is_active   =   $result['is_active'];

            }
       
    }
    
    public function query_array(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname) . " WHERE version_id = {$this->db->escape($this->id)} AND is_active={$this->db->escape(1)}", "array");
        return  $result;
    }
    
    public function query_numrows(){
        $result = $this->db->query("SELECT * FROM " . $this->db->tbl_name($this->tblname), "numrows");
        return $result;
    }
    
    public function save() {
        $insert_array = array(
            //"id"                =>  $this->id,
            "campaign_id"           =>  $this->campaign_id,	
            "user_id"               =>  $this->user_id,
            "date_created"          =>  $this->date_created,
            "version_name"          =>  $this->version_name,
            "version"               =>  $this->version,
            "quarter"               =>  $this->quarter,
            "title"             =>  $this->title,
            "campaign_list_id"  =>  $this->campaign_list_id,	
            "brand_story"       =>  $this->brand_story,
            "description"       =>  $this->description,
            "is_active"             =>  $this->is_active
            
        );
    
        $insert_id = $this->db->insert($this->db->tbl_name($this->tblname), $insert_array);
    
        $this->id = $insert_id;
    }
    //
    public function update() {
        $update_array = array(
            "campaign_id"           =>  $this->campaign_id,	
            "user_id"               =>  $this->user_id,
            "date_created"          =>  $this->date_created,
            "version_name"          =>  $this->version_name,
            "version"               =>  $this->version,
            "quarter"               =>  $this->quarter,
            "title"                 =>  $this->title,
            "campaign_list_id"      =>  $this->campaign_list_id,	
            "brand_story"           =>  $this->brand_story,
            "description"           =>  $this->description,
            "is_active"             =>  $this->is_active
        );
    
        $condition_array = array("version_id" => $this->id);
    
        $this->db->update($this->db->tbl_name($this->tblname), $update_array, $condition_array);
    }
}

?>
